#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1 
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef int Status;
typedef char SElemType;
typedef struct
{
    SElemType * base;
    SElemType * top;
    int stacksize;
}SqStack;
Status InitStack(SqStack &S)
{
    S.base = (SElemType *)malloc(STACK_INIT_SIZE * sizeof(SElemType));
    if (!S.base) exit(ERROR);
    S.top = S.base;
    S.stacksize = STACK_INIT_SIZE;
    return OK;
}
Status Push(SqStack &S, SElemType &e)
{
    if (S.top - S.base >= S.stacksize)
    {
        S.base = (SElemType *)realloc(S.base, (STACK_INIT_SIZE + STACKINCREMENT) * sizeof(SElemType));
        if (!S.base)
            return OVERFLOW;
        S.top = S.base + S.stacksize;
        S.stacksize += STACKINCREMENT;
    }
    *S.top++ = e;
    return OK;
}
Status Pop(SqStack &S, SElemType &e)
{
    if (S.top == S.base)
        return ERROR;
    e = *--S.top;
    return OK;
}
Status ClearStack(SqStack &S)
{
    S.top = S.base;
    return OK;
}
Status DestroyStack(SqStack &S)
{
    free(S.base);
    return OK;
}
void visit(SElemType * ptr)
{
    printf("%c", *ptr);
}
void StackTraverse(SqStack &S)
{
    SElemType * p;
    for (p = S.base; p < S.top; p++)
        visit(p);
}
// p50 algorithm 3.2
void LineEdit()
{
    SqStack S;
    InitStack(S);
    char ch = getchar();
    while (ch != EOF)
    {
        while (ch != EOF && ch != '\n')
        {
            SElemType e;
            switch(ch)
            {
                case '#': Pop(S, e);break;
                case '@': ClearStack(S);break;
                default: Push(S, ch);
            }
            ch = getchar();
        }
        StackTraverse(S);
        printf("进入缓冲区");
        ClearStack(S);
        if (ch != EOF)
            ch = getchar();
    }
    DestroyStack(S);
}
int main(void)
{
    LineEdit();

    return 0;
}